﻿using Forum.BaseController;
using Forum.Service.Interface;

namespace Forum.Controllers
{
    /// <summary>
    /// 访问记录
    /// </summary>
    [Route("Api/VisitRecord")]
    public class VisitRecordController : BaseController<IVisitRecordService>
    {
        public VisitRecordController(IVisitRecordService defaultService, ILogger<BaseController<IVisitRecordService>> logger) : base(defaultService, logger)
        {
        }

        /// <summary>
        /// 批量查询访问记录
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiResponsePaged<VisitRecord> GetList([FromQuery] VisitRecordQueryParameters param)
        {
            var pagedList = DefaultService.GetPagedList(param);
            return new ApiResponsePaged<VisitRecord>(pagedList);
        }

        /// <summary>
        /// 查询访问记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id:int}")]
        public ApiResponse<VisitRecord> GetById(int id)
        {
            var item = DefaultService.GetById(id);
            return item == null ? ApiResponse.NotFound() : new ApiResponse<VisitRecord>(item);
        }

        /// <summary>
        /// 获取全部访问记录
        /// </summary>
        /// <returns></returns>
        [HttpGet("All")]
        public ApiResponse<List<VisitRecord>> GetAll()
        {
            return new ApiResponse<List<VisitRecord>>(DefaultService.GetAll());
        }

        /// <summary>
        /// 总览数据
        /// </summary>
        /// <returns></returns>
        [HttpGet("[action]")]
        public ApiResponse Overview()
        {
            return ApiResponse.OK("", DefaultService.Overview());
        }

        /// <summary>
        /// 趋势数据
        /// </summary>
        /// <param name="days">查看最近几天的数据，默认7天</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        public ApiResponse Trend(int days = 7)
        {
            return ApiResponse.OK("", DefaultService.Trend(days));
        }

        /// <summary>
        /// 统计接口
        /// </summary>
        /// <returns></returns>
        [HttpGet("[action]")]
        public ApiResponse Stats(int year, int month, int day)
        {
            var date = new DateTime(year, month, day);
            return ApiResponse.OK("", DefaultService.Stats(date));
        }
    }
}
